fix(perf): keep gpt-oss decode in bf16#17
Merged
Conversation
GptOss SwiGLU now mirrors the mlx-lm activation path with a compiled activation-only helper and casts the result back to the input dtype, preventing FP32 promotion through the expert down projection on single-token decode. The MoE router now uses precise softmax and casts expert scores/results back to the expert/input dtype so residual state remains BF16 across layers. The M5 Max gpt-oss-120b-4bit benchmark improves from 19.49 tok/s to 112.83 tok/s, exceeding the 110.35 tok/s mlx-lm baseline.
3 tasks
This was referenced May 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GptOss single-token decode was promoting activations to FP32 inside the expert MLP and router, breaking the BF16 fast path and causing a 5–6× throughput regression versus mlx-lm.
Impact
On M5 Max,
gpt-oss-120b-4bitdecode throughput:mlxcel now slightly exceeds the mlx-lm Python baseline on this workload.
Files Touched
src/lib/mlxcel-core/cpp/mlx_cxx_bridge.{cpp,h}— new compiled activation helpersrc/lib/mlxcel-core/src/lib.rs+ffi_tests.rs— Rust binding + FFI testsrc/models/gpt_oss.rs— SwiGLU dtype preservation, router precise softmax + dtype castsTest plan
cargo test -p mlxcel-core(FFI activation helper)gpt-oss-120b-4bitdecode benchmark on M5 Max — 112.83 tok/s (was 19.49)